<template>
  <div class="group-table-box">
    <Row class="group-top">
      <Col span="16" class="group-top">
        <div class="input-item input-flex">
          <span>商品名称：</span>
          <Input v-model="form.groupName" placeholder="商品名称" style="width: 100px;" />
        </div>

        <div class="input-item input-flex">
          <span>商品分类：</span>
          <Input v-model="form.createName" placeholder="商品分类" style="width: 100px;" />
        </div>

        <div class="input-item input-flex">
          <span>创建时间：</span>
          <DatePicker
            v-model="form.date"
            type="daterange"
            format="yyyy-MM-dd"
            confirm
            placement="bottom-start"
            placeholder="创建时间"
            style="width: 200px"
            @on-change="onClickDatePickerChange"
          ></DatePicker>
        </div>

        <div class="input-item">
          <Button type="info" class="input-btn" @click="onClickSearch">搜索</Button>
          <Button type="warning" class="input-btn" @click="onClickReset">重置搜索</Button>
        </div>
      </Col>

      <Col span="8" class="group-right">
        <div class="input-item" style="margin-right: 0;">
          <Button type="info" @click="clickAddModal">新增商品</Button>
        </div>
      </Col>
    </Row>
    <div class="table-container">
      <Table
        border
        class="table-container-table"
        :columns="columns7"
        :data="tableData"
        :loading="isLoading"
      ></Table>
      <Page
        :total="totalPageCount"
        :current="form.pageIndex"
        :page-size="10"
        show-elevator
        class="table-container-page"
        @on-change="getTableData"
      />
    </div>

    <!-- 点击新增活动 -->
    <Modal
      v-model="showAddModal"
      width="50"
      footer-hide
    >
      <div class="modal-container">
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">商品名称</p>
          </Col>
          <Col span="20">
            <Input v-model="form.name" placeholder="请输入..." />
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">商品分类</p>
          </Col>
          <Col span="20">
            <Select v-model="form.class">
              <Option value="撒钱活动">撒钱活动</Option>
              <Option value="VIP活动">VIP活动</Option>
            </Select>
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">商品邮费</p>
          </Col>
          <Col span="20">
            <Input v-model="form.name" placeholder="请输入...">
              <span slot="append">元</span>
            </Input>
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">商品原价</p>
            <p class="modal-label-detail">（含税）</p>
          </Col>
          <Col span="20">
            <Input v-model="form.name" placeholder="请输入...">
              <span slot="append">元</span>
            </Input>
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">商品折扣价</p>
            <p class="modal-label-detail">（含税）</p>
          </Col>
          <Col span="20">
            <Input v-model="form.name" placeholder="请输入...">
              <span slot="append">元</span>
            </Input>
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">推荐说明</p>
            <p class="modal-label-detail">（若不填写则不展示）</p>
          </Col>
          <Col span="20">
            <Input v-model="form.levelInfo" type="textarea" :rows="4" placeholder="请输入..." />
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">商品说明</p>
            <p class="modal-label-detail">（单张图尺寸建议222*222，至多可上传8张）</p>
          </Col>
          <Col span="20">
            <Upload
              type="drag"
              action="/"
            >
              <div style="padding: 70px 0">
                <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
                <p>点击上传图片</p>
              </div>
            </Upload>
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">是否展示优秀测评</p>
          </Col>
          <Col span="20">
            <i-switch>
              <span slot="open">开</span>
              <span slot="close">关</span>
            </i-switch>
          </Col>
        </Row>
        <Row class="modal-content" :gutter="16">
          <Col span="4">
            <p class="modal-label">是否展示销售量</p>
          </Col>
          <Col span="20">
            <i-switch>
              <span slot="open">开</span>
              <span slot="close">关</span>
            </i-switch>
          </Col>
        </Row>
        <div slot="footer" class="modal-footer">
          <Button type="primary" @click="onClickAddConfirm">完成</Button>
        </div>
      </div>
    </Modal>
  </div>
</template>

<script>
export default {
  data () {
    return {
      switch1: false,
      showAddModal: false,
      isLoading: false,
      form: {
        pageIndex: 1,
      },
      totalPageCount: 10,
      columns7: [
        {
          title: '序号',
          type: 'index',
          align: 'center'
        },
        {
          title: '商品名称',
          key: 'groupName',
          align: 'center'
        },
        {
          title: '创建时间',
          key: 'issueTime',
          align: 'center'
        },
        {
          title: '所属商品分类',
          key: 'userName',
          align: 'center'
        },
        {
          title: '是否精选',
          key: 'price',
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('i-switch', { //数据库1是已处理，0是未处理
                props: {
                  type: 'primary',
                  //控制开关的打开或关闭状态，官网文档属性是value
                  value: this.tableData[params.index].isDelete == '1' ? false : true,
                  size: 'large'
                },
                scopedSlots: {
                    close: function (props) {
                        return '禁用'
                    },
                    open: function (props) {
                        return '启用'
                    }
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  'on-change': (value) => {//触发事件是on-change,用双引号括起来，
                                           //参数value是回调值，并没有使用到
                    this.switch(params.index, value) //params.index是拿到table的行序列，可以取到对应的表格值
                  }
                }
              },)
            ])
          }
        },
        {
          title: '初始价格',
          key: 'tagListLabel',
          align: 'center'
        },
        {
          title: '折扣价',
          key: 'groupStatusText',
          align: 'center'
        },
        {
          title: '已售量',
          key: 'groupStatusText',
          align: 'center'
        },
        {
          title: '操作',
          key: 'action',
          width: 280,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  margin: '5px',
                  width: '70px'
                },
                on: {
                  click: () => {
                    this.check(params.index)
                  }
                }
              }, '修改'),
              h('Button', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                style: {
                  margin: '5px',
                  width: '70px'
                },
                on: {
                  click: () => {
                    this.success(params.index)
                  }
                }
              }, '删除'),
              h('i-switch', { //数据库1是已处理，0是未处理
                props: {
                  type: 'primary',
                  //控制开关的打开或关闭状态，官网文档属性是value
                  value: this.tableData[params.index].isDelete == '1' ? false : true,
                  size: 'large'
                },
                scopedSlots: {
                    close: function (props) {
                        return '禁用'
                    },
                    open: function (props) {
                        return '启用'
                    }
                },
                style: {
                  marginLeft: '5px'
                },
                on: {
                  'on-change': (value) => {//触发事件是on-change,用双引号括起来，
                                           //参数value是回调值，并没有使用到
                    this.switch(params.index, value) //params.index是拿到table的行序列，可以取到对应的表格值
                  }
                }
              },)
            ]);
          }
        }
      ],
      tableData: [{
        groupStatusText: '123123'
      }],
      checkReturnData: {
      }
    }
  },
  mounted() {
    this.getTableData();
  },
  watch: {
  },
  methods: {
    onClickSearch() {

    },
    onClickReset() {

    },
    onClickDeleteConfirm() {

    },
    clickAddModal() {
      // 点击新增商品
      this.showAddModal = true
    },
    check(index) {
      //  点击修改按钮
      this.showAddModal = true
    },
    onClickAddConfirm() {

    },
    success(index) {

    },
    remove(index) {

    },
    getTableData(index) {

    },
    onClickDatePickerChange(e) {
      // ["2018-08-07", "2018-09-12"]
      // this.form.date = e;
    },
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.input-flex {
  display: inline-flex !important;
  flex-direction: column;
}
.pull-right {
  float: right;
}
.group-table-box {
  padding: 20px;
}
.group-top {
  display: flex;
  align-items: flex-end;
}
.group-right {
  display: flex;
  justify-content: flex-end;
}
.input-item {
  display: inline-block;
  margin: 0 20px 20px 0;
  color: #000;
}
.input-btn {
  margin-right: 10px;
}
.table-container-page {
  text-align: center;
  margin-top: 20px;
  color: #000;
}
.modal-container {
  padding: 30px 30px 20px 30px;
}
.modal-content {
  margin-top: 15px;
}
.modal-label {
  font-size: 14px;
  text-align: center;
}
.modal-label-detail {
  text-align: center;
}
.modal-input {
  width: 100%;
}
.modal-footer {
  text-align: center;
  margin-top: 15px;
}
.modal-footer button {
  color: #fff;
  width: 100px;
}
</style>
